package com.sc.portal.controller;

import com.sc.common.pojo.CommonResult;
import com.sc.pojo.TbItem;
import com.sc.portal.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

/**
 * @auther sc
 * @Date 2017/10/27
 */
@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/item/{itemID}")
    public String getItem(@PathVariable(value = "itemID")Long itemID, Model model){
        TbItem result = itemService.getItemById(itemID);
        if(result.getImage()!=null&&result.getImage()!=""){
            String str = result.getImage();
            String[] arr = str.split(",");
            model.addAttribute("img",arr);
        }else {
            model.addAttribute("img",new ArrayList());
        }
        model.addAttribute("item",result);
        return "item";
    }

    @RequestMapping(value = "/item/desc/{itemID}",produces = MediaType.TEXT_HTML_VALUE+";charset=utf-8")
    @ResponseBody
    public String getItemDesc(@PathVariable(value = "itemID")Long itemID){
        String desc = itemService.getItemDesc(itemID);
        return desc;

    }
    @RequestMapping(value = "/item/param/{itemID}",produces = MediaType.TEXT_HTML_VALUE+";charset=utf-8")
    @ResponseBody
    public String getItemParam(@PathVariable(value = "itemID")Long itemID){
        String table = itemService.getdetail(itemID);
        return table;
    }

}
